﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL = Auto.Data.BusMan.BLL;
using Model = Auto.Data.BusMan.Model;
using System.Data;

namespace Auto.BusMan.AddForm
{
    public partial class fmCarAccidentAddForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }

        private void InitPage()
        {
            string docid = Request.QueryString["DocID"];
            BindData(docid);
        }

        private void BindData(string docid)
        {
            BLL.BusAccident bl = new BLL.BusAccident();
            Model.BusAccident model = bl.GetModel(docid);

            //this.lblBusID.Text = model.BusID;
            //this.lblCompanyID.Text = model.CompanyID;
            this.lblBusIdentificationNO.Text = model.BusIdentificationNO;
            this.lblCompanyName.Text = model.CompanyName;
            //this.lblDriverID.Text = model.DriverID;
            this.lblDriverName.Text =GetDriverName(model.DriverID);
            this.lblAccidentTime.Text = model.AccidentTime.ToString("yyyy-MM-dd");
            this.lblAccidentAddress.Text = model.AccidentAddress;
            this.lblAccidentDesc.Text = model.AccidentDesc;
            this.ucAccidentPicFileShow.FileList = model.AccidentPic;// this.lblAccidentPic.Text = model.AccidentPic;
            this.lblAccidentResponsibility.Text = model.AccidentResponsibility;
            this.ucTrafficPoliceDispositionFileShow.FileList = model.TrafficPoliceDisposition;// this.lblTrafficPoliceDisposition.Text = model.TrafficPoliceDisposition;
            this.lblTrafficProcessRecord.Text = GetAccidentProcess(model.DocID);// model.TrafficProcessRecord;
            //this.litTrafficProcessRecord.Text = model.TrafficProcessRecord;
            this.lblTotalCost.Text = model.TotalCost.ToString();
            this.lblInsurancePay.Text = model.InsurancePay.ToString();
            this.lblAdversePartyPay.Text = model.AdversePartyPay.ToString();
            this.lblDriverPay.Text = model.DriverPay.ToString();
            this.lblCompanyPay.Text = model.CompanyPay.ToString();
            this.lblCompleteDate.Text =model.CompleteDate.ToString("yyyy-MM-dd");

        }

        private string GetDriverName(string driverid)
        {
            //Driver
            BLL.Drivers bllDrivers = new BLL.Drivers();
            Model.Drivers modelDrivers = bllDrivers.GetModel(driverid);
            if (modelDrivers != null)
            {
               return modelDrivers.DriverName;
            }
            else
            {
                return "未知姓名";
            }
        }

        private string GetAccidentProcess(string docID)
        {
            BLL.BusAccidentProcess bll = new BLL.BusAccidentProcess();
            DataTable  dt= bll.GetListByRefDocID(docID);
            string s = string.Empty;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                s += dt.Rows[i][Model.BusAccidentProcess.FIELD_RecID].ToString()+"." + dt.Rows[i][Model.BusAccidentProcess.FIELD_TrafficProcessRecord].ToString() + ";</br>";
            }

            return s;

        }
    }
}